package com.app.java.url;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;

public class UrlTest {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		URL url = new URL("http://localhost:8080/utils/parseXml.url.jsp");
		HttpURLConnection conn = null;
		String hubxml= "";
		for(int i=0;i<10;i++){
			hubxml="<?xml version='1.0'?>"+
			"<MT>  "+
			"	<USER_NAME>324</USER_NAME>  "+
			"	<PASSWORD>423</PASSWORD>  "+
			"	<TRX_ID>=========== TestURL " + i + " ===========</TRX_ID>	<!-- MTDetail.hubs_mt_id -->"+
			"	<MSISDN>+32476957733</MSISDN>  "+
			"	<PRICE>0</PRICE>  "+
			"	<DCS>7b</DCS>  "+
			"	<ACK_LEVEL>1</ACK_LEVEL>  "+
			"	<ACK_URL>http://mthubresponse2.funmobilebe.com/MTResponse</ACK_URL>  "+
			"	<OPERATOR_ID>3202</OPERATOR_ID>  "+
			"	<TEXT>Nog steeds geinteresseerd in jouw item? Stuur nu"+
			"YES naar 3377. Help: 02-6260025</TEXT>"+
			"	<CONTENT_TYPE_ID>117</CONTENT_TYPE_ID>"+
			"	<PRIORITY>0</PRIORITY>"+
			"</MT>";
			
			conn = (HttpURLConnection) url.openConnection();
			conn.setRequestMethod("POST");
			conn.setDoOutput(true);
			conn.setDoInput(true);
			conn.setReadTimeout(5000);
			conn.setConnectTimeout(5000);
			conn.connect();

			// send request
			BufferedOutputStream urlOut = new BufferedOutputStream(conn.getOutputStream());
			PrintWriter pw = new PrintWriter(urlOut);
			pw.println(hubxml);
			pw.flush();
			pw.close();
			
			
			urlOut.write(hubxml.getBytes("ISO-8859-1"));
			urlOut.flush();
			urlOut.close();
			
			BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			String str = null;
			while ((str = br.readLine()) != null)
				System.out.println(str);
		}
	}

}
